
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort.*;
import io.swagger.annotations.*;
import java.util.*;

import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;
import com.huizhan.web.view.*;

/**
 * 头像api
 */
 
@Api(tags = "ProjectAvatar",description = "头像")
@RestController
public class ProjectAvatarController {
    
    @Autowired
    private ProjectAvatarDao dao;
   
    /**
     * 获取头像集合
     * @return api结果
     */
    @ApiOperation(value = "获取头像集合")
    @RequestMapping(value =  "/api/ProjectAvatar/",method = {RequestMethod.GET})
    public ApiResult<List<ProjectAvatar>> Get(){
         ApiResult<List<ProjectAvatar>> result=new ApiResult<List<ProjectAvatar>>();
        try 
        {
            List<ProjectAvatar> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取头像信息
     * @param id 头像ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/{id}",method = {RequestMethod.GET})
    public ApiResult<ProjectAvatar> Get(@PathVariable Long id){
        ApiResult<ProjectAvatar> result=new ApiResult<ProjectAvatar>();
        try
        {
            ProjectAvatar model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 查询赠票集合
     * @param model 账号信息
     * @return api结果
     */
    @ApiOperation(value = "查询赠票集合")
    @RequestMapping(value =  "/api/ProjectAvatar/Search",method = {RequestMethod.POST})
    public ApiResult<List<ProjectAvatar>> Search(@RequestBody PageProjectAvatar model){
         ApiResult<List<ProjectAvatar>> result=new ApiResult<List<ProjectAvatar>>();
         
        try
        {    
            PageRequest pageable = PageRequest.of(model.getPageIndex(),model.getPageSize(),Direction.DESC,"Project_Avatar_Id") ;            
            Page<ProjectAvatar> page = dao.findByWhere(model.getName(),model.getCode(),model.getProjectId(),model.getDocumentTypeId(),model.getTicketTypeId(),pageable);
            result.setData(page.getContent());
            result.setTotal(page.getTotalElements());
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        
        return result;
    }

    /**
     * 修改头像信息
     * @param id 头像ID
     * @param model 头像信息
     * @return api结果
     */
    @ApiOperation(value = "修改头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/{id}",method = {RequestMethod.PUT})
    public ApiResult<ProjectAvatar> Edit(@PathVariable Long id,@RequestBody ProjectAvatar model){
        ApiResult<ProjectAvatar> result=new ApiResult<ProjectAvatar>();
        try
        {
            model.setProjectAvatarId(id);
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 添加头像信息
     * @param model 头像信息
     * @return api结果
     */
    @ApiOperation(value = "添加头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/",method = {RequestMethod.POST})
    public ApiResult<ProjectAvatar> Add(@RequestBody ProjectAvatar model){
         ApiResult<ProjectAvatar> result=new ApiResult<ProjectAvatar>();
        try
        {
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除头像信息
     * @param id 头像ID
     * @return api结果
     */
    @ApiOperation(value = "删除头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除头像信息
     * @param ticketTypeId 票类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据票类型ID删除头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/TicketType/{ticketTypeId}",method = {RequestMethod.DELETE})
    public ApiResult<Object> DeleteByTicketTypeId(@PathVariable Long ticketTypeId){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteByTicketTypeId(ticketTypeId);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 根据证件类型删除头像信息
     * @param documentTypeId 证件类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据证件类型ID删除头像信息")
    @RequestMapping(value =  "/api/ProjectAvatar/DocumentType/{documentTypeId}",method = {RequestMethod.DELETE})
    public ApiResult<Object> DeleteByDocumentTypeId(@PathVariable Long documentTypeId){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteByDocumentTypeId(documentTypeId);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

